package com.call.net;

import java.io.IOException;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.call.Constants;

public class NetUtils {
	private static String baseUrl = "http://192.168.0.1/CallInfo/";
	private static HttpClient client = new DefaultHttpClient();
	public static String getRandomText()
	{
		String functionUrl = "GetFirstRandom.php";
		HttpGet request = new HttpGet(baseUrl + functionUrl);
		try {
			HttpResponse response = client.execute(request);
			String retSrc = EntityUtils.toString(response.getEntity());
			JSONObject result = new JSONObject( retSrc);
			String randomText = result.getString("random-text");
			return randomText;
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			Log.i(Constants.Tag,"get random text caught ClientProtocolException");
			return null;
		} catch (IOException e) {
			// TODO Auto-generated catch block
			Log.i(Constants.Tag,"get random text caught IOException");
			return null;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			Log.i(Constants.Tag,"get random text caught JSONException");
			return null;
		}
		
	}
}
